package com.bwie.task;

import com.bwie.exception.BusinessException;
import com.bwie.mapper.StoreMapper;
import com.bwie.mq.MessageProducer;
import com.bwie.pojo.Store;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SpringTask {

    @Autowired
    private StoreMapper storeMapper ;

    @Autowired
    private MessageProducer messageProducer ;

    @Scheduled(cron = "0 0 0 * * ?")
    public void selectStore(){
        List<Store> list = storeMapper.select();

        if(ObjectUtils.isEmpty(list)){
            throw new BusinessException("暂无数据");
        }

        for(Store store : list){
            //将查询到的数据放入生产者中
            messageProducer.sendToMsg(store);
        }
    }
}
